from django.contrib.auth.models import User, Group

from rat.models import Document, Requirement, OneLineText, Section, MultiLineText, Table, Alias, Image, File, Archive

from random import random

order=0
for gi in range(11):
   g=Group(name='project_%s' % gi)
   g.save()
   for di in range(7):
      d=Document(project=g, name='doc%d' %di, prefix='p%d'%di )
      d.save()
   for ui in range(3):
      uname = 'user_%s_%s' % (gi,ui)
      u=User.objects.create_user(uname, '%s@%s.com' % (uname, g), 'snow')
      u.first_name ='first%s' %gi
      u.last_name = 'last%s' %ui
      u.save()
      u.groups.add(g)
      for ri in range(17):
         for d in Document.objects.filter(project=g):
            r=Requirement(document=d, order=order, user=u)
            if random()>0.95:
               r.active = False
            if random()>0.95:
               r.writeable = False
            r.save()
            order+=1
            if random()>0.2:
               x=OneLineText(requirement=r, text='blah%d' %order)
               x.save()
            if random()>0.5:
               x=MultiLineText(requirement=r, text='%s\n2\n\3\n' %order)
               x.save()
            if random()>0.8:
               x=Section(requirement=r, kind='%s' % (order%10), text='heading %s' %order)
               x.save()
            if random()>0.9:
               x=Table(requirement=r, text='a,b,c\n1,2,3\n3,4,5')
               x.save()
               

